package com.itcam.cm.manager.controller;

import cn.hutool.http.server.HttpServerResponse;
import com.alibaba.excel.EasyExcel;
import com.itcam.cm.manager.service.CategoryService;
import com.itcam.cm.model.entity.product.Category;
import com.itcam.cm.model.vo.common.Result;
import com.itcam.cm.model.vo.product.CategoryExcelVo;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping(value="/admin/product/category")
@CrossOrigin(allowCredentials = "true" , originPatterns = "*" , allowedHeaders = "*")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping(value = "/findByParentId/{parentId}")
    public Result<List<Category>> findByParentId(@PathVariable Long parentId) {
        List<Category> list = categoryService.findByParentId(parentId);
        return Result.ok(list) ;
    }

    @PostMapping("importData")
    public Result importData(@RequestParam("file")MultipartFile multipartFile){
        categoryService.importData(multipartFile);
        return  Result.ok(null) ;
    }

    @GetMapping("exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }
}